<template>
  <div class>
    <el-dialog :title="title" :visible.sync="dialogFormVisible" width="1000px" @close="close">
      <div class="ba_f">
        <div class="shuju_title mar_b20">
          <div class="shuju_title_text">
            <span>服务费率</span>
          </div>
        </div>
        <el-form ref="form" :model="form" label-width="180px" class="mar_t20">
          <el-form-item label="平台抽佣模式">
            <el-radio-group v-model="form.rule">
              <el-radio label="1">按系统默认设置</el-radio>
              <el-radio label="2">自定义抽佣设置</el-radio>
            </el-radio-group>
            <div class="yb_margin lh16">默认按照平台统一抽佣，如需单独给子门店设置抽佣比率，请选择自定义模式</div>
          </el-form-item>
          <el-form-item label="佣金计算方式" v-if="form.rule=='2'">
            <el-radio-group v-model="form.type">
              <el-radio label="1">订单百分比抽成</el-radio>
              <el-radio label="2">按固定金额</el-radio>
            </el-radio-group>
          </el-form-item>
<!--          <el-form-item label="结算周期">-->
<!--            <el-input v-model.trim="form.entryDay" autocomplete="off" placeholder="请输入结算周期">-->
<!--              <template slot="append">天</template>-->
<!--            </el-input>-->
<!--          </el-form-item>-->
          <div v-if="form.rule=='2' && form.type=='1'">
            <el-form-item label="商品抽佣比例">
              <el-input v-model="form.goodsPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <!--                                        <el-input v-model="form.name" style="width: 220px">-->
              <!--                                            <template slot="prepend">区域抽佣</template>-->
              <!--                                            <template slot="append">%</template>-->
              <!--                                        </el-input>-->
              <el-input v-model="form.goodsStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.goodsDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="配送费抽佣比例">
              <el-input v-model="form.deliverPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">%</template>-->
              <!--                                    </el-input>-->
              <el-input v-model="form.deliverStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.deliverDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="包装费抽佣比例">
              <el-input v-model="form.boxPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">%</template>-->
              <!--                                    </el-input>-->
              <el-input v-model="form.boxStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.boxDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="当面付抽佣比例">
              <el-input v-model="form.cashierPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <el-input v-model="form.cashierStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.cashierDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="快餐抽佣比例">
              <el-input v-model="form.fastPlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <el-input v-model="form.fastStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.fastDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="店内抽佣比例">
              <el-input v-model="form.inStorePlatformProportion" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">%</template>
              </el-input>
              <el-input v-model="form.inStoreStoreProportion" disabled style="width: 220px">
                <template slot="prepend">分店获得</template>
                <template slot="append">%</template>
              </el-input>/
              <el-input v-model="form.inStoreDownMoney" style="width: 220px">
                <template slot="prepend">最低抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </div>
          <div v-if="form.rule=='2' && form.type=='2'">
            <el-form-item label="商品抽成金额">
              <el-input v-model="form.goodsFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">元</template>-->
              <!--                                    </el-input>-->
            </el-form-item>
            <el-form-item label="配送费抽成金额">
              <el-input v-model="form.deliverFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">元</template>-->
              <!--                                    </el-input>-->
            </el-form-item>
            <el-form-item label="包装费抽成金额">
              <el-input v-model="form.boxFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
              <!--                                    <el-input v-model="form.name" style="width: 220px">-->
              <!--                                        <template slot="prepend">区域抽佣</template>-->
              <!--                                        <template slot="append">元</template>-->
              <!--                                    </el-input>-->
            </el-form-item>
            <el-form-item label="当面付抽成金额">
              <el-input v-model="form.cashierFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="快餐抽成金额">
              <el-input v-model="form.fastFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="店内抽成金额">
              <el-input v-model="form.inStoreFixedMoney" style="width: 220px">
                <template slot="prepend">总店抽佣</template>
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </div>
          <div class="shuju_title mar_b20">
            <div class="shuju_title_text">
              <span>子商户设置</span>
            </div>
          </div>
          <el-form-item label="子商户号">
            <el-radio-group v-model="form.sonService">
              <el-radio label="1">开启</el-radio>
              <el-radio label="2">关闭</el-radio>
            </el-radio-group>
            <div class="yb_margin lh16">开启子商户号后，用户微信付款的订单直接入账到当前商户号里，此模式下平台抽佣设置无效，余额支付的订单不受影响</div>
          </el-form-item>
          <el-form-item label="服务商子商户号" v-show="form.sonService=='1'">
            <el-input placeholder="请输入服务商子商户号" v-model="form.subMchId"></el-input>
            <div class="yb_margin lh16">请填写此门店的服务商子商户号</div>
          </el-form-item>
          <el-form-item label="服务商分账" v-show="form.sonService=='1'">
            <el-radio-group v-model="form.profit_sharing">
              <el-radio label="Y">开启</el-radio>
              <el-radio label="N">关闭</el-radio>
            </el-radio-group>
            <div class="yb_margin lh16">服务商分账需要先开启子商户功能，开启分账后，商家订单完成后会向指定的子商户号进行分账打款(分账比例按照服务费率来计算)</div>
          </el-form-item>
          <el-form-item label="分账商户号" v-show="form.sonService=='1' && form.profit_sharing=='Y'">
            <el-input placeholder="请输入分账商户号" v-model="form.giveMchid"></el-input>
            <div class="yb_margin lh16">请填写接受平台佣金的微信商户号</div>
          </el-form-item>
          <el-form-item label="分账商户号商户全称" v-show="form.sonService=='1' && form.profit_sharing=='Y'">
            <el-input placeholder="请输入分账商户号商户全称" v-model="form.giveName"></el-input>
            <div class="yb_margin lh16">请填写接受平台佣金的微信商户号全称，此名称要和微信商户后台保持一致</div>
          </el-form-item>
        </el-form>
      </div>
      <!--                <div class="mar_t20 ba_f pad_20 t_c">-->
      <!--                    <el-button type="primary" @click="submitForm">保存</el-button>-->
      <!--                </div>-->
      <div slot="footer" class="dialog-footer">
        <el-button size="medium" @click="close">取 消</el-button>
        <el-button size="medium" type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getStoreConfig, postStoreConfig } from '@/api/setup';
export default {
  created() {
    // this.init();
  },
  data() {
    return {
      form: {
        rule: '1',
        type: '2',
        goodsPlatformProportion: 0,
        goodsStoreProportion: 100,
        goodsDownMoney: 0,
        deliverPlatformProportion: 0,
        deliverStoreProportion: 100,
        deliverDownMoney: 0,
        boxPlatformProportion: 0,
        boxStoreProportion: 100,
        boxDownMoney: 0,
        goodsFixedMoney: 0,
        deliverFixedMoney: 0,
        boxFixedMoney: 0,
        entryDay: '',

        cashierPlatformProportion: 0,
        cashierStoreProportion: 100,
        cashierDownMoney: 0,
        cashierFixedMoney: 0,
        fastPlatformProportion: 0,
        fastStoreProportion: 100,
        fastDownMoney: 0,
        fastFixedMoney: 0,
        inStorePlatformProportion: 0,
        inStoreStoreProportion: 100,
        inStoreDownMoney: 0,
        inStoreFixedMoney: 0,

        sonService: '2',
        profit_sharing: 'N',
        subMchId: '',
        giveMchid: '',
        giveName: ''
      },
      storeId: '',
      title: '',
      dialogFormVisible: false
    };
  },
  methods: {
    showEdit(row) {
      this.storeId = row.id;
      this.init();
      if (!row) {
        this.title = '服务费率设置';
      } else {
        this.title = '服务费率设置';
        // this.form.goodsModel = row.goodsModel
      }
      this.dialogFormVisible = true;
    },
    close() {
      this.$refs['form'].resetFields();
      this.form = this.$options.data().form;
      this.dialogFormVisible = false;
    },
    async init() {
      const { data } = await getStoreConfig({ ident: 'serviceCharge', storeId: this.storeId });
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
      this.form.goodsStoreProportion = 100 - this.form.goodsPlatformProportion;
      this.form.deliverStoreProportion = 100 - this.form.deliverPlatformProportion;
      this.form.boxStoreProportion = 100 - this.form.boxPlatformProportion;
      this.form.cashierStoreProportion = 100 - this.form.cashierPlatformProportion;
      this.form.fastStoreProportion = 100 - this.form.fastPlatformProportion;
      this.form.inStoreStoreProportion = 100 - this.form.inStorePlatformProportion;
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form.ident = 'serviceCharge';
          this.form.storeId = this.storeId;
          this.form.identName = '商家费率设置';
          const { msg } = await postStoreConfig(this.form);
          this.$baseMessage(msg, 'success');
          this.$emit('fetchData');
          this.close();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
